#include <sys_config.h>
#include <types.h>
#include <basic_types.h>
#include <mediatypes.h>
#include <api/libc/printf.h>
#include <api/libc/string.h>
#include <osal/osal.h>
#ifndef NEW_DEMO_FRAME
#include <api/libpub29/lib_pub27.h>
#include <api/libpub29/lib_as.h>
#else
#include <api/libpub/lib_frontend.h>
#endif
#include <api/libdiseqc/lib_diseqc.h>

#include <api/libosd/osd_lib.h>

#include "osdobjs_def.h"
#include "string.id"
#include "images.id"
#include "osd_config.h"

#include "menus_root.h"
#include "win_com.h"
#include "win_com_popup.h"
#include "win_com_list.h"
#include "win_signalstatus.h"
#include "win_signal.h"

#ifdef SUPPORT_CAS_A
#include "win_com_menu_define.h"
#endif

#define FIRST_MOVE_BY_STEP
#define MAX_POSNUM	63

#define DBG_PRINTF PRINTF//soc_printf
/*******************************************************************************
*	Objects definition
*******************************************************************************/
extern CONTAINER g_win_motorset;


extern CONTAINER 	motorset_item1;	/* Satellite*/
extern CONTAINER 	motorset_item2;	/* TP */
extern CONTAINER 	motorset_item3;	/* Pos & Save */

extern TEXT_FIELD	motorset_txt1;
extern TEXT_FIELD 	motorset_txt2;
extern TEXT_FIELD 	motorset_txt3;
extern TEXT_FIELD 	motorset_txtbtn_gotonn;
extern TEXT_FIELD 	motorset_txtbtn_move;
extern TEXT_FIELD 	motorset_txtbtn_recal;

extern TEXT_FIELD	motorset_line1;
extern TEXT_FIELD 	motorset_line2;
extern TEXT_FIELD 	motorset_line3;

extern MULTISEL 	motorset_sel1;
extern MULTISEL 	motorset_sel2;
extern EDIT_FIELD 	motorset_edf3;

extern TEXT_FIELD 	motorset_txtinfo;
extern BITMAP		motorset_bmpinfo;



static VACTION motorset_item_sel_keymap(POBJECT_HEAD pObj, UINT32 key);
static PRESULT motorset_item_sel_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);

static VACTION motorset_item_edf_keymap(POBJECT_HEAD pObj, UINT32 key);
static PRESULT motorset_item_edf_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);

static VACTION motorset_item_keymap(POBJECT_HEAD pObj, UINT32 key);
static PRESULT motorset_item_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);

static VACTION motorset_itembtn_keymap(POBJECT_HEAD pObj, UINT32 key);
static PRESULT motorset_itembtn_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);

static VACTION motorset_keymap(POBJECT_HEAD pObj, UINT32 key);
static PRESULT motorset_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);


#define WIN_SH_IDX	  WSTL_WIN_BODYRIGHT_01_HD
#define WIN_HL_IDX	  WSTL_WIN_BODYRIGHT_01_HD
#define WIN_SL_IDX	  WSTL_WIN_BODYRIGHT_01_HD
#define WIN_GRY_IDX  WSTL_WIN_BODYRIGHT_01_HD

#define CON_SH_IDX   WSTL_BUTTON_01_HD
#define CON_HL_IDX   WSTL_BUTTON_05_HD
#define CON_SL_IDX   WSTL_BUTTON_01_HD
#define CON_GRY_IDX  WSTL_BUTTON_07_HD

#define TXT_SH_IDX   WSTL_BUTTON_01_FG_HD
#define TXT_HL_IDX   WSTL_BUTTON_02_FG_HD
#define TXT_SL_IDX   WSTL_BUTTON_01_FG_HD
#define TXT_GRY_IDX  WSTL_BUTTON_07_HD

#define SEL_SH_IDX   WSTL_BUTTON_01_FG_HD
#define SEL_HL_IDX   WSTL_BUTTON_04_HD
#define SEL_SL_IDX   WSTL_BUTTON_01_FG_HD
#define SEL_GRY_IDX  WSTL_BUTTON_07_HD

#define BTN_SH_IDX   WSTL_BUTTON_SHOR_HD
#define BTN_HL_IDX   WSTL_BUTTON_SHOR_HI_HD
#define BTN_SL_IDX   WSTL_BUTTON_01_FG_HD
#define BTN_GRY_IDX  WSTL_BUTTON_SHOR_GRY_HD

#define TXTINFO_SH_IDX   WSTL_BUTTON_02_FG_HD
#define TXTINFO_HL_IDX   WSTL_BUTTON_01_FG_HD
#define TXTINFO_SL_IDX   WSTL_BUTTON_01_FG_HD
#define TXTINFO_GRY_IDX  WSTL_BUTTON_07_HD

#define BMPINFO_SH_IDX   WSTL_BUTTON_01_HD
#define BMPINFO_HL_IDX   WSTL_BUTTON_01_HD
#define BMPINFO_SL_IDX   WSTL_BUTTON_01_HD
#define BMPINFO_GRY_IDX  WSTL_BUTTON_01_HD

#ifndef SD_UI
#ifndef SUPPORT_CAS_A
/* define in win_com_menu_define.h already */
#define	W_L     	248
#define	W_T     	98
#define	W_W     	692
#define	W_H     	488
#endif

#define CON_L		(W_L+20)
#define CON_T		(W_T + 4)
#define CON_W		(W_W - 60)
#define CON_H		40
#define CON_GAP		12

#define TXT_L_OF  	10
#define TXT_W  		280
#define TXT_H		CON_H
#define TXT_T_OF	((CON_H - TXT_H)/2)

#define SEL_L_OF  	(TXT_L_OF + TXT_W)
#define SEL_W  		(CON_W-TXT_W-20)
#define SEL_H		CON_H
#define SEL_T_OF	((CON_H - SEL_H)/2)

#define LINE_L_OF	0
#define LINE_T_OF  	(CON_H+4)
#define LINE_W		CON_W
#define LINE_H     	4

#define BTN_L		(W_L + 140)
#define BTN_T		(CON_T + (CON_H + CON_GAP)*3 + 30)
#define BTN_W		320
#define BTN_H		40
#define BTN_GAP		12

#define BMPINFO_L1	(BTN_L - BMPINFO_W - 10)
#define BMPINFO_L2 	(BTN_L + BTN_W + 10)
#define BMPINFO_T	(BTN_T + (BTN_H + BTN_GAP)*1)
#define BMPINFO_W	40
#define BMPINFO_H	40

#define TXTINFO_L1	(BMPINFO_L1 - TXTINFO_W)
#define TXTINFO_L2 (BMPINFO_L2 + BMPINFO_W)
#define TXTINFO_T	BMPINFO_T
#define TXTINFO_W	80
#define TXTINFO_H	40
#else
#define	W_L     	105//384
#define	W_T     	57//138
#define	W_W     	482
#define	W_H     	370

#define CON_L		(W_L+20)
#define CON_T		(W_T + 4)
#define CON_W		(W_W - 30)
#define CON_H		32
#define CON_GAP		4

#define TXT_L_OF  	10
#define TXT_W  		180
#define TXT_H		CON_H
#define TXT_T_OF	((CON_H - TXT_H)/2)

#define SEL_L_OF  	(TXT_L_OF + TXT_W)
#define SEL_W  		(CON_W-TXT_W-20)
#define SEL_H		CON_H
#define SEL_T_OF	((CON_H - SEL_H)/2)

#define LINE_L_OF	0
#define LINE_T_OF  	(CON_H+4)
#define LINE_W		CON_W
#define LINE_H     	4

#define BTN_L		(W_L + 140)
#define BTN_T		(CON_T + (CON_H + CON_GAP)*3 + 30)
#define BTN_W		150
#define BTN_H		32
#define BTN_GAP		10

#define BMPINFO_L1	(BTN_L - BMPINFO_W - 10)
#define BMPINFO_L2 	(BTN_L + BTN_W + 10)
#define BMPINFO_T	(BTN_T + (BTN_H + BTN_GAP)*1)
#define BMPINFO_W	30
#define BMPINFO_H	30

#define TXTINFO_L1	(BMPINFO_L1 - TXTINFO_W)
#define TXTINFO_L2 (BMPINFO_L2 + BMPINFO_W)
#define TXTINFO_T	BMPINFO_T
#define TXTINFO_W	60
#define TXTINFO_H	30

#endif


#define LDEF_CON(root, varCon,nxtObj,ID,IDl,IDr,IDu,IDd,l,t,w,h,conobj,focusID)		\
    DEF_CONTAINER(varCon,root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,IDl,IDr,IDu,IDd, l,t,w,h, CON_SH_IDX,CON_HL_IDX,CON_SL_IDX,CON_GRY_IDX,   \
    motorset_item_keymap,motorset_item_callback,  \
    conobj, ID,1)
    
#define LDEF_TXT(root,varTxt,nxtObj,l,t,w,h,resID)		\
    DEF_TEXTFIELD(varTxt,root,nxtObj,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, TXT_SH_IDX,TXT_HL_IDX,TXT_SL_IDX,TXT_GRY_IDX,   \
    NULL,NULL,  \
    C_ALIGN_LEFT | C_ALIGN_VCENTER, 0,0,resID,NULL)

#define LDEF_MSEL(root, varNum, nxtObj, ID, l, t, w, h,style,cur,cnt,ptabl)	\
    DEF_MULTISEL(varNum,root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,ID,ID,ID,ID, l,t,w,h, SEL_SH_IDX,SEL_HL_IDX,SEL_SL_IDX,SEL_GRY_IDX,   \
    motorset_item_sel_keymap,motorset_item_sel_callback,  \
    C_ALIGN_CENTER | C_ALIGN_VCENTER, 30,0,style,ptabl,cur,cnt)
    

#define LDEF_EDIT(root, varNum, nxtObj, ID, l, t, w, h,style,cursormode,pat,pre,sub,str)	\
    DEF_EDITFIELD(varNum,root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,ID,ID,ID,ID, l,t,w,h,  SEL_SH_IDX,SEL_HL_IDX,SEL_SL_IDX,SEL_GRY_IDX,   \
    motorset_item_edf_keymap,motorset_item_edf_callback,  \
    C_ALIGN_CENTER | C_ALIGN_VCENTER, 10,0,style,pat,10,cursormode,pre,sub,str)


#define LDEF_MENU_ITEM_SEL(root,varCon,nxtObj,varTxt,varNum,varLine,ID,IDu,IDd,\
						l,t,w,h,resID,style,cur,cnt,ptbl) \
    LDEF_CON(&root,varCon,nxtObj,ID,ID,ID,IDu,IDd,l,t,w,h,&varTxt,ID)   \
    LDEF_TXT(&varCon,varTxt,&varNum,l + TXT_L_OF,t + TXT_T_OF,TXT_W,TXT_H,resID)    \
    LDEF_MSEL(&varCon,varNum,NULL/*&varLine*/   ,ID, l + SEL_L_OF ,t + SEL_T_OF,SEL_W,SEL_H,style,cur,cnt,ptbl)\
	LDEF_LINE(&varCon,varLine,NULL,1,1,1,1,1,l + LINE_L_OF, t + LINE_T_OF,LINE_W,LINE_H,0,0)


#define LDEF_MENU_ITEM_EDF(root,varCon,nxtObj,varTxt,varEdf,varLine,ID,IDu,IDd,l,t,w,h,\
						resID,style,cursormode,pat,pre,sub,str) \
    LDEF_CON(&root,varCon,nxtObj,ID,ID,ID,IDu,IDd,l,t,w,h,&varTxt,ID)   \
    LDEF_TXT(&varCon,varTxt,&varEdf,l + TXT_L_OF,t + TXT_T_OF,TXT_W,TXT_H,resID)    \
    LDEF_EDIT(&varCon,varEdf,NULL/*&varLine*/   ,ID,l + SEL_L_OF ,t + SEL_T_OF,SEL_W,SEL_H,style,cursormode,pat,pre,sub,str)\
	LDEF_LINE(&varCon,varLine,NULL,1,1,1,1,1,l + LINE_L_OF, t + LINE_T_OF,LINE_W,LINE_H,0,0)


#define LDEF_TXT_BTN(root,varTxt,nxtObj,ID,IDu,IDd,l,t,w,h,resID)		\
    DEF_TEXTFIELD(varTxt,&root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,ID,ID,IDu,IDd, l,t,w,h, BTN_SH_IDX,BTN_HL_IDX,BTN_SL_IDX,BTN_GRY_IDX,   \
    motorset_itembtn_keymap,motorset_itembtn_callback,  \
    C_ALIGN_CENTER| C_ALIGN_VCENTER, 0,0,resID,NULL)

#define LDEF_TXT_INFO(root,varTxt,l,t,w,h,resID)		\
    DEF_TEXTFIELD(varTxt,&root,NULL,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, TXTINFO_SH_IDX,TXTINFO_HL_IDX,TXTINFO_SL_IDX,TXTINFO_GRY_IDX,   \
    NULL,NULL,  \
    C_ALIGN_CENTER| C_ALIGN_VCENTER, 0,0,resID,NULL)


#define LDEF_BMP_INFO(root,varBmp,l,t,w,h,icon)		\
  DEF_BITMAP(varBmp,&root,NULL,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, BMPINFO_SH_IDX,BMPINFO_HL_IDX,BMPINFO_SL_IDX,BMPINFO_GRY_IDX,   \
    NULL,NULL,  \
    C_ALIGN_CENTER | C_ALIGN_VCENTER, 0,0,icon)


#define LDEF_WIN(varCon,nxtObj,l,t,w,h,focusID)		\
    DEF_CONTAINER(varCon,NULL,NULL,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, WIN_SH_IDX,WIN_HL_IDX,WIN_SL_IDX,WIN_GRY_IDX,   \
    motorset_keymap,motorset_callback,  \
    nxtObj, focusID,0)


#define WIN  g_win_motorset

extern char sat_pos_pat[];

//Sat
LDEF_MENU_ITEM_SEL(WIN,motorset_item1,&motorset_item2,motorset_txt1,motorset_sel1, motorset_line1,1, 6, 2, \
		CON_L, CON_T + (CON_H + CON_GAP)*0, CON_W, CON_H, RS_INFO_SATELLITE, STRING_PROC, 0, 0, NULL)
//Tp
LDEF_MENU_ITEM_SEL(WIN,motorset_item2,&motorset_item3,motorset_txt2,motorset_sel2,motorset_line2, 2, 1, 3, \
		CON_L, CON_T + (CON_H + CON_GAP)*1, CON_W, CON_H, RS_INFO_TRANSPONDER, STRING_PROC, 0, 0, NULL)
//Pos
LDEF_MENU_ITEM_EDF(WIN,motorset_item3,&motorset_txtbtn_gotonn,motorset_txt3,motorset_edf3, motorset_line3,3, 2, 4, \
		CON_L, CON_T + (CON_H + CON_GAP)*2, CON_W, CON_H, RS_DISEQC12_POSITION_NUMBER, NORMAL_EDIT_MODE,CURSOR_NO, sat_pos_pat,NULL,NULL,display_strs[0])

//Goto nn
LDEF_TXT_BTN(WIN,motorset_txtbtn_gotonn,&motorset_txtbtn_move,  4,3,5,\
		BTN_L, BTN_T + (BTN_H + BTN_GAP)*0, BTN_W, BTN_H,RS_DISEQC12_MODE_GOTOX)

//Movement & Save
LDEF_TXT_BTN(WIN,motorset_txtbtn_move,&motorset_txtbtn_recal,  5,4,6,\
		BTN_L, BTN_T + (BTN_H + BTN_GAP)*1, BTN_W, BTN_H,RS_COMMON_SAVE)

//Recalculation
LDEF_TXT_BTN(WIN,motorset_txtbtn_recal,NULL                     ,  6,5,1,\
		BTN_L, BTN_T + (BTN_H + BTN_GAP)*2, BTN_W, BTN_H,RS_DISEQC12_RECALCULATION)

LDEF_TXT_INFO(WIN, motorset_txtinfo,TXTINFO_L1, TXTINFO_T, TXTINFO_W, TXTINFO_H, 0)
LDEF_BMP_INFO(WIN, motorset_bmpinfo,BMPINFO_L1, BMPINFO_T, BMPINFO_W, BMPINFO_H,0)

LDEF_WIN(WIN,&motorset_item1,W_L, W_T, W_W, W_H,1)


#define SAT_ID	1
#define TP_ID	2
#define POS_ID	3
#define GOTONN_ID	4
#define MOVESAVE_ID	5
#define RECACULATE_ID	6


#define SAT_IDX (motorset_sel1.nSel)
#define TP_IDX (motorset_sel2.nSel)

#define SAT_CNT  (motorset_sel1.nCount)
#define TP_CNT (motorset_sel2.nCount)

/*******************************************************************************
*	Local vriable & function declare
*******************************************************************************/

char sat_pos_pat[]  = "r0~63";

static UINT8 tone_voice_init;

UINT8	diskmotor_move_state;/* 0 - not move, 1-move west, 2-move east */
UINT8	diskmotor_move_step; /* 0 - step move, 1-continue move*/
extern UINT8	antset_cur_tuner;


#define MOVE_TIERR_NAME "mov"
#define MOVE_TIERR_TIME    400

static ID diskmove_timer_id = OSAL_INVALID_ID;
static void win_disk_move_handler(UINT32 nouse);


// state - 0 normal, 1 - move west, 1-move east
void win_motorset_draw_info(UINT32 state);
void win_motorset_movebtn_setstr(UINT32 stop);
void win_motorset_movebtn_draw(UINT32 state);

static void win_motorset_load_sat(UINT32 sat_idx,BOOL update);

static void win_motorset_set_frontend(void);
static void win_motorset_turn_tp(void);

UINT16 win_motorset_gotonn_sub_list(void);

static PRESULT	win_motorset_message_proc(UINT32 msg_type, UINT32 msg_code);

/*******************************************************************************
*	key mapping and event callback definition
*******************************************************************************/

static VACTION motorset_item_sel_keymap(POBJECT_HEAD pObj, UINT32 key)
{
	VACTION act = VACT_PASS;

	switch(key)
	{
	case V_KEY_LEFT:
		act = VACT_DECREASE;
		break;
	case V_KEY_RIGHT:
		act = VACT_INCREASE;
		break;
	case V_KEY_ENTER:
		act = VACT_ENTER;
		break;
	}

	return act;
}

static PRESULT motorset_item_sel_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;
	VACTION unact;
	
	UINT32 sel;
	UINT16* Uni_str;
	UINT8 bID;

	COM_POP_LIST_TYPE_T list_type;
	OSD_RECT rect;
	COM_POP_LIST_PARAM_T param;
	S_NODE s_node;
	UINT16 cur_idx;
	UINT8 back_saved;
	

	bID = OSD_GetObjID(pObj);

	switch(event)
	{
	case EVN_REQUEST_STRING:
		sel = param1;
		Uni_str= (UINT16*)param2;
		if(bID == SAT_ID)
			get_tuner_sat_name(antset_cur_tuner,sel,Uni_str);
		else //TP_ID
		{
			get_tuner_sat(antset_cur_tuner,SAT_IDX,&s_node);
			get_tp_name(s_node.sat_id,sel,Uni_str);
		}
		break;
	case EVN_POST_CHANGE:
		sel = param1;

SAT_TP_CHANGED:
		/* Need to turn SAT/TP here*/
		if(bID == SAT_ID)
		{
			win_motorset_load_sat(SAT_IDX,TRUE);
			win_motorset_set_frontend();
			get_tuner_sat(antset_cur_tuner,SAT_IDX,&s_node);			
			wincom_dish_move_popup_open(0xFFFF,s_node.sat_id,antset_cur_tuner,&back_saved);			
		}
		else
		{
			win_motorset_turn_tp();
		}
		
		break;
	case EVN_UNKNOWN_ACTION:
		unact = (VACTION)(param1>>16);
		if(unact == VACT_ENTER)
		{
			param.selecttype = POP_LIST_SINGLESELECT;

			OSD_SetRect2(&rect,&pObj->frame);	
			rect.uLeft -= 40;
			rect.uWidth += 40;

			if(bID == SAT_ID)
			{
				list_type = POP_LIST_TYPE_SAT;
				list_type = POP_LIST_TYPE_SAT;
				rect.uHeight = 300;
				param.id = antset_cur_tuner;
				param.cur = SAT_IDX;				
			}
			else// if(bID == TP_ID)
			{
				list_type = POP_LIST_TYPE_TP;
				list_type = POP_LIST_TYPE_TP;
				rect.uHeight = 300;
				get_tuner_sat(antset_cur_tuner,SAT_IDX,&s_node);
				param.id = s_node.sat_id;
				param.cur = TP_IDX;
			}
			
			cur_idx = win_com_open_sub_list(list_type,&rect,&param);
			if(cur_idx == LIST_INVALID_SEL_IDX || cur_idx == param.cur)
				break;
			
			if(bID == SAT_ID)
				SAT_IDX = cur_idx;
			else
				TP_IDX = cur_idx;
			OSD_TrackObject(pObj, C_DRAW_SIGN_EVN_FLG | C_UPDATE_ALL);
			
			sel = cur_idx;
			
			goto SAT_TP_CHANGED;
		}
		
		break;
	}


	return ret;
}

static VACTION motorset_item_edf_keymap(POBJECT_HEAD pObj, UINT32 key)
{
	VACTION act = VACT_PASS;

 	switch(key)
	{
	case V_KEY_0:	case V_KEY_1:	case V_KEY_2:	case V_KEY_3:
	case V_KEY_4:	case V_KEY_5:	case V_KEY_6:	case V_KEY_7:
	case V_KEY_8:	case V_KEY_9:
		act = key - V_KEY_0 + VACT_NUM_0;
		break;
	case V_KEY_LEFT:
		act = VACT_EDIT_LEFT;
		break;
	case V_KEY_RIGHT:
		act = VACT_EDIT_RIGHT;
		break;
 	}

	return act;
}

static PRESULT motorset_item_edf_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;
	
	switch(event)
    {
    case EVN_PRE_CHANGE:
		break;
 	}

	return ret;
}

static VACTION motorset_item_keymap(POBJECT_HEAD pObj, UINT32 key)
{
	VACTION act = VACT_PASS;

	return act;
}

static PRESULT motorset_item_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;

	return ret;
}

#define VACT_MOVE_WEST (VACT_PASS + 1)
#define VACT_MOVE_EAST (VACT_PASS + 2)

static VACTION motorset_itembtn_keymap(POBJECT_HEAD pObj, UINT32 key)
{
	VACTION act = VACT_PASS;

	switch(key)
	{
	case V_KEY_LEFT:
		act = VACT_MOVE_WEST;
		break;
	case V_KEY_RIGHT:
		act = VACT_MOVE_EAST;
		break;
	case V_KEY_ENTER:
		act = VACT_ENTER;
		break;
	}

	return act;
}

static PRESULT motorset_itembtn_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;
	VACTION unact;
	UINT8 bID;
	UINT8 back_saved;
	win_popup_choice_t choice;
	UINT32 position,sat_pos;
	struct nim_device *nim_dev;
	S_NODE s_node;

	nim_dev = antset_cur_tuner==0? g_nim_dev : g_nim_dev2;
	

	bID = OSD_GetObjID(pObj);

	switch(event)
	{
	case EVN_UNKNOWN_ACTION:
		unact = (VACTION)(param1>>16);

		if(unact == VACT_MOVE_WEST || unact == VACT_MOVE_EAST)
		{
			if(bID != MOVESAVE_ID)	break;

			if(diskmotor_move_state == 0 )
			{
				if(unact == VACT_MOVE_WEST)
				{
#ifdef FIRST_MOVE_BY_STEP				
					api_diseqc_drive_motor_west_by_steps(nim_dev,1,0);
					diskmotor_move_step = 0;
#else
					api_diseqc_drive_motor_west(nim_dev,0);
#endif
					diskmotor_move_state = 1;
				}
				else	//VACT_MOVE_EAST
				{
#ifdef FIRST_MOVE_BY_STEP				
					api_diseqc_drive_motor_east_by_steps(nim_dev,1,0);
					diskmotor_move_step = 0;
#else
					api_diseqc_drive_motor_east(nim_dev,0);
#endif					
					diskmotor_move_state = 2;				
				}

				api_stop_timer(&diskmove_timer_id);
                osal_task_sleep(100);
				DBG_PRINTF("Start move %d\n",diskmotor_move_state);
				diskmove_timer_id = api_start_timer(MOVE_TIERR_NAME, MOVE_TIERR_TIME,win_disk_move_handler);
				

SET_MOVE_DISPLAY:
				win_motorset_draw_info(diskmotor_move_state);
				win_motorset_movebtn_setstr(1);
				win_motorset_movebtn_draw(1);				
			}
			else
			{
				if( (diskmotor_move_state == 1 && unact == VACT_MOVE_WEST)
					|| (diskmotor_move_state ==2 && unact == VACT_MOVE_EAST))
				{	
					/* Continue move West or East*/
					DBG_PRINTF("Continue move %d\n",diskmotor_move_state);

#ifdef FIRST_MOVE_BY_STEP
					api_stop_timer(&diskmove_timer_id);
					if(diskmotor_move_step == 0)
					{
						osal_task_sleep(100);
						if(diskmotor_move_state== 1)
							api_diseqc_drive_motor_west(nim_dev,0);
						else
							api_diseqc_drive_motor_east(nim_dev,0);
						diskmotor_move_step = 1;
						DBG_PRINTF("First time continue move\n");
					}
                    //else
					//    DBG_PRINTF("Continue move %d\n",diskmotor_move_state);
#endif
					osal_task_sleep(100);
					diskmove_timer_id = api_start_timer(MOVE_TIERR_NAME, MOVE_TIERR_TIME,win_disk_move_handler);
				
				}
				else
					goto STOP_MOVE;
			}
			
		}
		else if(unact == VACT_ENTER)
		{			
			if(bID == MOVESAVE_ID)
			{
				if(diskmotor_move_state != 0)
					goto STOP_MOVE;
				else
				{
					/* Save current postion */
					OSD_GetEditFieldIntValue(&motorset_edf3,&position);

					get_tuner_sat(antset_cur_tuner,SAT_IDX,&s_node);
					if(position<=MAX_POSNUM)
					{
						sat_pos = antset_cur_tuner==0? s_node.position : s_node.tuner2_antena.position;

						if(sat_pos == position && position== 0)
						{
							win_compopup_init(WIN_POPUP_TYPE_OK);
							win_compopup_set_msg("Position not specified (1~63)", NULL, 0);
							win_compopup_open_ext(&back_saved);
							break;
						}
					
						win_compopup_init(WIN_POPUP_TYPE_OKNO);
						if(position == 0)
							win_compopup_set_msg("Are you sure to clear this satellite's position?", NULL, 0);
						else
							win_compopup_set_msg("Are you sure to change this satellite's position?", NULL, 0);							
						choice = win_compopup_open_ext(&back_saved);
						if(choice == WIN_POP_CHOICE_YES)
						{
							if(sat_pos != position)
							{
								recreate_sat_view(VIEW_ALL,0);
								if(antset_cur_tuner == 0)
									s_node.position = position;
								else
									s_node.tuner2_antena.position = position;
								modify_sat(s_node.sat_id, &s_node);
								update_data();
							}

							if(position != 0)
								api_diseqc_store_satellite_position(nim_dev, (UINT8)position,0);
						}
					}
					else
					{
						
					}
				}
			}
			else if(bID == GOTONN_ID)
			{
			
				position = (UINT32)win_motorset_gotonn_sub_list();
				if(position <= MAX_POSNUM)
				{
					if(position == 0)
						api_diseqc_goto_reference(nim_dev,0);
					else
						api_diseqc_goto_satellite_position(nim_dev,position,0);
					win_compopup_init(WIN_POPUP_TYPE_OK);
					win_compopup_set_msg("Wait to move the position!", NULL, 0);
                    win_compopup_set_btnstr(0, RS_DISEQC12_MOVEMENT_STOP);
					win_compopup_open_ext(&back_saved);
					api_diseqc_halt_motor(nim_dev,0);					
				}
				
			}
			else if(bID == RECACULATE_ID)
			{
				get_tuner_sat(antset_cur_tuner,SAT_IDX,&s_node);
				sat_pos = antset_cur_tuner==0? s_node.position : s_node.tuner2_antena.position;

				if(sat_pos == 0)
				{
					win_compopup_init(WIN_POPUP_TYPE_SMSG);
					win_compopup_set_msg("Position is NULL", NULL,0);
					win_compopup_open_ext(&back_saved);
					osal_task_sleep(500);
					win_compopup_smsg_restoreback();
				}
                else
                {
    				win_compopup_init(WIN_POPUP_TYPE_OKNO);
    				win_compopup_set_msg("Are you sure re-calulate all satellite positions?", NULL, 0);
    				choice = win_compopup_open_ext(&back_saved);
    				if(choice == WIN_POP_CHOICE_YES)
    					api_diseqc_calculate_satellite_position(nim_dev,sat_pos,0,0, 0);
                }


			}
				
		}
		
		break;
	case EVN_UNKNOWNKEY_GOT:

		//if(bID == MOVESAVE_ID)
		if(diskmotor_move_state)
		{
STOP_MOVE:
			DBG_PRINTF("Stoped\n");
			api_stop_timer(&diskmove_timer_id);
			osal_task_sleep(50);
			api_diseqc_halt_motor(nim_dev,0);
			diskmotor_move_state = 0;

			win_motorset_draw_info(diskmotor_move_state);
			win_motorset_movebtn_setstr(0);
			win_motorset_movebtn_draw(1);
		}
		
		break;
	}
	return ret;
}

static VACTION motorset_keymap(POBJECT_HEAD pObj, UINT32 key)
{
	VACTION act;
	switch(key)
	{
  	case V_KEY_UP:
        act = VACT_CURSOR_UP;
        break;
    case V_KEY_DOWN:
        act = VACT_CURSOR_DOWN;
		break;
	case V_KEY_EXIT:
	case V_KEY_MENU:
		act = VACT_CLOSE;
		break;
	default:
		act = VACT_PASS;
	}

	return act;	
}

extern UINT8 beep_bin_array[];
extern UINT32 beep_bin_array_size;

static PRESULT motorset_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;
	S_NODE s_node;
	UINT8 back_saved;
	UINT16 title_strid;
	POBJECT_HEAD sat_item = (POBJECT_HEAD)&motorset_item1;
	POBJECT_HEAD tp_item = (POBJECT_HEAD)&motorset_item2;
	
	SYSTEM_DATA* sys_data;
	sys_data = sys_data_get();

	get_tuner_sat(antset_cur_tuner,SAT_IDX,&s_node);

	switch(event)
	{
	case EVN_PRE_OPEN:
		tone_voice_init = 0;
		diskmotor_move_state = 0;
		diskmove_timer_id = OSAL_INVALID_ID;

		SAT_CNT = get_tuner_sat_cnt(antset_cur_tuner);
		SAT_IDX = 0;

		win_motorset_load_sat(SAT_IDX,FALSE);
		if(sys_data->tuner_lnb_type[antset_cur_tuner] != LNB_MOTOR)
			return PROC_LEAVE;
		if(sys_data->tuner_lnb_antenna[antset_cur_tuner].motor_type == LNB_MOTOR_DISEQC12)
		{
			title_strid = RS_MOTOR_SETTING;
			sat_item->bUpID 	= RECACULATE_ID;
			tp_item->bDownID 	= POS_ID;
			tp_item->pNext 		= (POBJECT_HEAD)&motorset_item3;			
		}
		else
		{
			title_strid = RS_MOTOR_SETTING;
			sat_item->bUpID 	= POS_ID;
			tp_item->bDownID 	= SAT_ID;
			tp_item->pNext 	= NULL;			
			
		}
		OSD_SetContainerFocus(&g_win_motorset, SAT_ID);
		
		
		wincom_open_title(pObj,title_strid,0);

		break;
	case EVN_POST_OPEN:
		win_motorset_set_frontend();
		//win_signal_open(pObj);
		#ifndef SD_UI
		win_signal_open_ex(pObj,pObj->frame.uLeft + 4,pObj->frame.uTop+pObj->frame.uHeight - 140);
		#else
		win_signal_open_ex(pObj,pObj->frame.uLeft + 4,pObj->frame.uTop+pObj->frame.uHeight - 80);
		#endif
		win_signal_refresh();
		//win_signal_update();		
		get_tuner_sat(antset_cur_tuner,SAT_IDX,&s_node);			
		wincom_dish_move_popup_open(0xFFFF,s_node.sat_id,antset_cur_tuner,&back_saved);		
		break;
	case EVN_PRE_CLOSE:
		/* Make OSD not flickering */
		*((UINT32*)param2) &= ~C_CLOSE_CLRBACK_FLG;	
		break;
	case EVN_POST_CLOSE:
		win_signal_close();
#ifdef ANTENNA_INSTALL_BEEP	
		if(sys_data->install_beep)
		{
		#if(defined(DVBT_BEE_TONE) && ANTENNA_INSTALL_BEEP == 1)
			api_audio_stop_tonevoice();
		#elif (defined(AUDIO_SPECIAL_EFFECT) && ANTENNA_INSTALL_BEEP == 2)
			api_audio_beep_stop();
		#endif
		}
#endif		
		break;		
	case EVN_POST_DRAW:
		if(tp_item->pNext != NULL)
			win_motorset_draw_info(diskmotor_move_state);
		break;
	case EVN_MSG_GOT:
		ret = win_motorset_message_proc(param1,param2);
		break;
		
	}

	return ret;
}


static PRESULT	win_motorset_message_proc(UINT32 msg_type, UINT32 msg_code)
{
	struct nim_device *nim_dev;
	UINT8 level,quality,lock;
	SYSTEM_DATA* sys_data;
	static UINT32 interval;

	sys_data = sys_data_get();

	nim_dev = antset_cur_tuner==0? g_nim_dev : g_nim_dev2;

	switch(msg_type)
	{
	case CTRL_MSG_SUBTYPE_STATUS_TIMEOUT:
		if(diskmotor_move_state)
		{
			DBG_PRINTF("Move time out\n");
            UINT32 count;
            for (count = 0; count < 4; count++)
            {
			    api_diseqc_halt_motor(nim_dev,0);
                osal_task_sleep(50);
            }
			diskmotor_move_state = 0;

			win_motorset_draw_info(diskmotor_move_state);
			win_motorset_movebtn_setstr(0);
			win_motorset_movebtn_draw(1);
            DBG_PRINTF("Move time out. Stopped\n");
		}

		break;
	case CTRL_MSG_SUBTYPE_STATUS_SIGNAL:
		win_signal_refresh();
		//win_signal_update();		

#ifdef ANTENNA_INSTALL_BEEP			
		if(sys_data->install_beep)
		{
			level   = (UINT8)(msg_code>>16);
			quality = (UINT8)(msg_code>>8);
			lock    = (UINT8)(msg_code>>0);
		#if(defined(DVBT_BEE_TONE) && ANTENNA_INSTALL_BEEP == 1)			
			if(quality<20)
	          	level = 0;
	        else if(quality<40)
	            level = 1;
	        else if(quality<55)
	            level = 3;
	        else if(quality <70)
	            level = 5;
	        else
	            level = 7;
			api_audio_gen_tonevoice(level, tone_voice_init);
		#elif (defined(AUDIO_SPECIAL_EFFECT) && ANTENNA_INSTALL_BEEP == 2)
			if(lock)
				level = 100;
			else
				level = 1;		
			if(!tone_voice_init || level!=interval)
			{
				if(!tone_voice_init)
					api_audio_beep_start(beep_bin_array,beep_bin_array_size);
				interval = level;
				api_audio_beep_set_interval(interval);					
			}
		#endif			
			tone_voice_init = 1;
		}
#endif			
		break;
	}

}


void win_motorset_draw_txtinfo(UINT32 pos,UINT32 state)
{
	TEXT_FIELD* txt;
	UINT8 style;
	UINT16 strID;

	txt = &motorset_txtinfo;

	txt->head.frame.uLeft = (pos == 0)? TXTINFO_L1 : TXTINFO_L2;
	txt->bAlign = (pos == 0)? (C_ALIGN_RIGHT | C_ALIGN_VCENTER) : (C_ALIGN_LEFT | C_ALIGN_VCENTER);

	strID = (state == 3)? 0 :  ( (pos==0)? RS_DISEQC12_MOVEMENT_WEST : RS_DISEQC12_MOVEMENT_EAST);
	OSD_SetTextFieldContent(txt,STRING_ID,strID);
	switch(state)
	{
	case 0:
		style = TXTINFO_SH_IDX;
		break;
	case 1:
		style = TXTINFO_HL_IDX;
		break;
	case 2:
		style = TXTINFO_SL_IDX;
		break;
	case 3:
	default:
		style = TXTINFO_GRY_IDX;		
	}

	OSD_SetColor(txt, style, style, style, style);
	OSD_DrawObject((POBJECT_HEAD)txt,C_UPDATE_ALL);
	 
}

extern UINT16 bmp_info_icons[][2];

void win_motorset_draw_bmpinfo(UINT32 pos,UINT32 state)
{
	BITMAP* bmp;
	UINT16 icon;

	bmp = &motorset_bmpinfo;
	bmp->head.frame.uLeft = (pos == 0)? BMPINFO_L1 : BMPINFO_L2;

	if(state>=2)
		icon = 0;
	else
		icon = bmp_info_icons[pos][state];
	
	OSD_SetBitmapContent(bmp, icon);

	OSD_DrawObject((POBJECT_HEAD)bmp,C_UPDATE_ALL);
}

// state - 0 normal, 1 - move west, 1-move east
void win_motorset_draw_info(UINT32 state)
{
	UINT32 txtl_state,txtr_state,bmpl_state,bmpr_state;

	if(state == 0)
	{
		txtl_state = txtr_state = 0;
		bmpl_state = bmpr_state = 0;
	}
	else if(state == 1)
	{
		txtl_state = 1;
		txtr_state = 0;
		bmpl_state = 1;
		bmpr_state = 0;
	}
	else// if(state == 2)
	{
		txtl_state = 0;
		txtr_state = 1;
		bmpl_state = 0;
		bmpr_state = 1;	
	}

	win_motorset_draw_txtinfo(0,txtl_state);
	win_motorset_draw_txtinfo(1,txtr_state);
	win_motorset_draw_bmpinfo(0,bmpl_state);
	win_motorset_draw_bmpinfo(1,bmpr_state);
}

void win_motorset_movebtn_setstr(UINT32 stop)
{
	TEXT_FIELD* txt;
	UINT16 strid;

	txt = &motorset_txtbtn_move;
	if(stop)
		strid = RS_DISEQC12_MOVEMENT_STOP;
	else
		strid = RS_COMMON_SAVE;//limit_btn_strids[LIMIT_OPT];
	OSD_SetTextFieldContent(txt , STRING_ID, strid);
}

void win_motorset_movebtn_draw(UINT32 state)
{
	TEXT_FIELD* txt;
	txt = &motorset_txtbtn_move;


	if(state == 0)
		OSD_DrawObject((POBJECT_HEAD)txt,C_UPDATE_ALL);
	else
		OSD_TrackObject((POBJECT_HEAD)txt,C_UPDATE_ALL);
}


static void win_disk_move_handler(UINT32 nouse)
{
	struct nim_device *nim_dev;

	nim_dev= antset_cur_tuner==0? g_nim_dev : g_nim_dev2;
	
	if(diskmove_timer_id != OSAL_INVALID_ID)
	{
		diskmove_timer_id = OSAL_INVALID_ID;
		if(diskmotor_move_state)
			ap_send_msg(CTRL_MSG_SUBTYPE_STATUS_TIMEOUT, 0, TRUE);
	}
}

static void win_motorset_load_sat(UINT32 sat_idx,BOOL update)
{
	S_NODE s_node;
	UINT16 tp_cnt,sat_pos;
	POBJECT_HEAD tp_item = (POBJECT_HEAD)&motorset_item2;
	

	get_tuner_sat(antset_cur_tuner,sat_idx,&s_node);
	tp_cnt = get_tp_num_sat(s_node.sat_id);

	sat_pos = antset_cur_tuner==0? s_node.position : s_node.tuner2_antena.position;
	

	TP_CNT = tp_cnt;
	TP_IDX = 0;

	if(sat_pos> 63)
		sat_pos = 0;
	OSD_SetEditFieldContent(&motorset_edf3, STRING_NUMBER, sat_pos);

	if(update)
	{
		OSD_DrawObject(tp_item, C_DRAW_SIGN_EVN_FLG | C_UPDATE_ALL);
		if(tp_item->pNext != NULL)
			OSD_DrawObject((POBJECT_HEAD)&motorset_item3, C_DRAW_SIGN_EVN_FLG | C_UPDATE_ALL);
	}
}

static UINT32 win_motorset_key_notify_proc(UINT32 msg_code)
{
    UINT32 vkey = ap_key_msg_code_to_vkey(msg_code);
    VACTION vact = motorset_item_sel_keymap(NULL, vkey);

    if (vact == VACT_PASS)
    {
        vact = motorset_keymap(NULL, vkey);
    }
    if (vact != VACT_PASS)
    { 
        nim_io_control(g_nim_dev, NIM_DRIVER_STOP_CHANSCAN, 1);
    }
    return 1;
}

static void win_motorset_set_frontend(void)
{
	S_NODE s_node;
	T_NODE t_node;
#ifdef NEW_DEMO_FRAME
	struct ft_antenna antenna;
	union ft_xpond	xpond_info;
#else
	struct cc_antenna_info antenna;
	struct cc_xpond_info	xpond_info;
#endif

	SYSTEM_DATA* sys_data;
	antenna_t* pAntenna;
    BOOL old_get_key;

    nim_io_control(g_nim_dev, NIM_DRIVER_STOP_CHANSCAN, 0);
    ap_set_key_notify_proc(win_motorset_key_notify_proc);
    old_get_key = ap_enable_key_task_get_key(TRUE);

    win_signal_set_level_quality(0, 0, 0);
    win_signal_update();
	OSD_UpdateVscr(OSD_GetTaskVscr(osal_task_get_current_id()));

	sys_data = sys_data_get();
	pAntenna = &sys_data->tuner_lnb_antenna[antset_cur_tuner];
	
	
	get_tuner_sat(antset_cur_tuner, SAT_IDX,&s_node);
	if(get_tp_num_sat(s_node.sat_id) == 0)
	{
		t_node.frq 	= 0;
		t_node.sym	= 0;
		t_node.pol	= 0;		
	}
	else
		get_tp_at(s_node.sat_id,TP_IDX,&t_node);
		
#ifndef NEW_DEMO_FRAME
	struct cc_antenna_info antenna;
	struct cc_xpond_info	xpond_info;

	sat2antenna_ext(&s_node, &antenna,antset_cur_tuner);
	antenna.lnb_type 	= pAntenna->lnb_type;
	antenna.lnb_low		= pAntenna->lnb_low;
	antenna.lnb_high	= pAntenna->lnb_high;
	
	xpond_info.frq = t_node.frq;
	xpond_info.sym = t_node.sym;
	xpond_info.pol = t_node.pol;

	set_antenna(&antenna);
	set_xpond(&xpond_info);
#else	
	MEMSET(&antenna, 0, sizeof(struct ft_antenna));
	MEMSET(&xpond_info, 0, sizeof(union ft_xpond));
#ifdef DVBS_SUPPORT
    sat2antenna(&s_node, &antenna);	
#endif
	antenna.lnb_type 	= pAntenna->lnb_type;
	antenna.lnb_low	= pAntenna->lnb_low;
	antenna.lnb_high	= pAntenna->lnb_high;
	xpond_info.s_info.type = FRONTEND_TYPE_S;
	xpond_info.s_info.frq = t_node.frq;
	xpond_info.s_info.sym = t_node.sym;
	xpond_info.s_info.pol = t_node.pol;
	xpond_info.s_info.tp_id = t_node.tp_id;
	struct nim_device *nim = (struct nim_device *)dev_get_by_id(HLD_DEV_TYPE_NIM, (s_node.tuner1_valid ? 0 : (s_node.tuner2_valid ? 1 : 0)));
    frontend_tuning(nim, &antenna, &xpond_info, 1);

#endif

    ap_enable_key_task_get_key(old_get_key);
    ap_set_key_notify_proc(NULL);
    nim_io_control(g_nim_dev, NIM_DRIVER_STOP_CHANSCAN, 0);
}

static void win_motorset_turn_tp(void)
{
	S_NODE s_node;
	T_NODE t_node;
	
#ifdef NEW_DEMO_FRAME
	struct ft_antenna antenna;
	union ft_xpond	xpond_info;
	
	get_tuner_sat(antset_cur_tuner, SAT_IDX,&s_node);
	if(get_tp_at(s_node.sat_id,TP_IDX,&t_node) != SUCCESS)
     		MEMSET(&t_node,0,sizeof(t_node));
	MEMSET(&antenna, 0, sizeof(struct ft_antenna));
	MEMSET(&xpond_info, 0, sizeof(union ft_xpond));
#ifdef DVBS_SUPPORT
	sat2antenna(&s_node, &antenna);	
#endif
	//sat2antenna_ext(&s_node, &antenna,antset_cur_tuner);
	
	xpond_info.s_info.type = FRONTEND_TYPE_S;
	xpond_info.s_info.frq = t_node.frq;
	xpond_info.s_info.sym = t_node.sym;
	xpond_info.s_info.pol = t_node.pol;
	xpond_info.s_info.tp_id = t_node.tp_id;

	struct nim_device *nim = (struct nim_device *)dev_get_by_id(HLD_DEV_TYPE_NIM, (s_node.tuner1_valid ? 0 : (s_node.tuner2_valid ? 1 : 0)));
	frontend_tuning(nim, &antenna, &xpond_info, 1);


#else
    BOOL old_get_key;

	struct cc_antenna_info antenna;
	struct cc_xpond_info	xpond_info;

    nim_io_control(g_nim_dev, NIM_DRIVER_STOP_CHANSCAN, 0);
    ap_set_key_notify_proc(win_motorset_key_notify_proc);
    old_get_key = ap_enable_key_task_get_key(TRUE);

    win_signal_set_level_quality(0, 0, 0);
    win_signal_update();
	OSD_UpdateVscr(OSD_GetTaskVscr(osal_task_get_current_id()));

	get_tuner_sat(antset_cur_tuner, SAT_IDX,&s_node);
	get_tp_at(s_node.sat_id,TP_IDX,&t_node);
	
	get_tuner_sat(antset_cur_tuner, SAT_IDX,&s_node);
	if(get_tp_at(s_node.sat_id,TP_IDX,&t_node) != SUCCESS)
     MEMSET(&t_node,0,sizeof(t_node));
	//sat2antenna(&s_node, &antenna);	
	sat2antenna_ext(&s_node, &antenna,antset_cur_tuner);
	
	xpond_info.frq = t_node.frq;
	xpond_info.sym = t_node.sym;
	xpond_info.pol = t_node.pol;

	//set_antenna(&antenna);
	set_xpond(&xpond_info);
    ap_enable_key_task_get_key(old_get_key);
    ap_set_key_notify_proc(NULL);
    nim_io_control(g_nim_dev, NIM_DRIVER_STOP_CHANSCAN, 0);
#endif
}

PRESULT comlist_position_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	UINT16 i,wTop;
    OBJLIST* ol;
	char str[50];
	UINT16 index;
	S_NODE s_node;
	UINT16	sat_pos;
	PRESULT cbRet = PROC_PASS;
	

	get_tuner_sat(antset_cur_tuner, SAT_IDX,&s_node);
	sat_pos = antset_cur_tuner==0? s_node.position : s_node.tuner2_antena.position;
	

    ol = (OBJLIST*)pObj;
	
	if(event==EVN_PRE_DRAW)
	{
    	wTop = OSD_GetObjListTop(ol);
    	for(i=0;i<ol->wDep && (i+wTop)<ol->wCount;i++)
    	{
    		index = i + wTop;
    		if(index == 0)
				STRCPY(str,"Reference");
			else if(index==sat_pos)
				sprintf(str,"%d(Stored)",index);
			else
				sprintf(str,"%d",index);
			
            win_comlist_set_str(index,str,NULL,0 );
    	}
	}
	else if(event == EVN_POST_CHANGE)
		cbRet = PROC_LEAVE;

	return cbRet;
}

UINT16 win_motorset_gotonn_sub_list(void)
{
	struct OSDRect rect;
	UINT16 i,count,dep,cur_idx;
	UINT16 style;
	UINT8 mark_align,offset;
	PFN_KEY_MAP winkeymap;
	PFN_CALLBACK callback;
	UINT8 back_saved;
	UINT av_mode;
	POBJECT_HEAD pObj = (POBJECT_HEAD)&motorset_txtbtn_gotonn;

	count = MAX_POSNUM + 1;/* Reference + 1~63 */
	callback = comlist_position_callback;
	dep = 6;
	cur_idx = LIST_INVALID_SEL_IDX;
	OSD_SetRect2(&rect,&pObj->frame);
#ifndef SD_UI
	rect.uLeft = 500;
	rect.uTop= 200;
	rect.uWidth = 320;
	rect.uHeight = dep*40+80;
	offset = 40;
#else
	rect.uLeft = 300;
	rect.uTop= 150;
	rect.uWidth = 200;
	rect.uHeight = dep*30+70;
	offset = 30;
#endif
	
		
	style = LIST_VER | LIST_SCROLL | LIST_FOCUS_FIRST | LIST_PAGE_KEEP_CURITEM | LIST_FULL_PAGE;
	style |= LIST_SINGLE_SLECT;
	
	winkeymap = NULL;

	mark_align = C_ALIGN_RIGHT;
	win_comlist_reset();
	win_comlist_set_sizestyle(count, dep,style);
	if(style & LIST_MULTI_SLECT)
		win_comlist_set_align(30,0,C_ALIGN_LEFT | C_ALIGN_VCENTER);
	else
		win_comlist_set_align(10,4,C_ALIGN_LEFT | C_ALIGN_VCENTER);
	win_comlist_ext_enable_scrollbar(TRUE);
	win_comlist_set_frame(rect.uLeft,rect.uTop, rect.uWidth, rect.uHeight);
	win_comlist_set_mapcallback(NULL,winkeymap,callback);

	win_comlist_ext_set_ol_frame(rect.uLeft + 20,rect.uTop + 40/*30*/, rect.uWidth - 40, rect.uHeight - 80/*40*/);
	win_comlist_ext_set_selmark_xaligen(mark_align,offset);
	//win_comlist_ext_set_win_style(win_idx);
	//win_comlist_ext_set_ol_items_style( sh_idx,  hi_idx,  sel_idx);
	//win_comlist_ext_set_title(/*title_str*/NULL,NULL,title_id);
	win_comlist_ext_set_selmark(0);
	if(style & LIST_SINGLE_SLECT)
		win_comlist_ext_set_item_sel(cur_idx);
	win_comlist_ext_set_item_cur(cur_idx);

	win_comlist_popup_ext(&back_saved);

	return win_comlist_get_selitem();
}
